package com.developer.platform.controller.system;

import cn.hutool.http.Method;
import com.developer.platform.application.query.LogQueryManager;
import com.developer.platform.application.query.dto.LogDto;
import com.developer.platform.application.query.dto.ResponseModel;
import com.developer.platform.controller.BaseController;
import com.developer.platform.infrastructure.enums.StatusEnum;
import com.veeker.core.bean.Pageable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：qiaoliang
 * @date ：2021-01-07
 */
@Api(tags = "日志管理")
@Validated
@RequestMapping("/system/log")
@RestController
public class LogController extends BaseController {

  private final LogQueryManager logQueryManager;

  public LogController(
      LogQueryManager logQueryManager) {
    this.logQueryManager = logQueryManager;
  }

  @ApiOperation(value = "查询操作日志列表")
  @GetMapping
  public ResponseEntity<ResponseModel<LogDto>> operationLog(
      @RequestParam(value = "userId" , required = false) Long userId,
      @RequestParam(value = "methodName" , required = false) String methodName,
      @RequestParam(value = "businessType" , required = false) String businessType,
      @RequestParam(value = "method" , required = false) Method method,
      @RequestParam(value = "status" , required = false) StatusEnum status,
      @RequestParam(value = "discription" , required = false) String discription,
      Pageable pageable){
    return ok(logQueryManager.list(userId, methodName, businessType, method, status, discription, pageable));
  }

  @ApiOperation(value = "查询首页日志记录")
  @GetMapping("/index")
  public ResponseEntity<List<LogDto>> list(){
    return ok(logQueryManager.list());
  }

}
